import EnemyControl from "./EnemyControl";
import WallControl from "./WallControl";

const {ccclass, property} = cc._decorator;

@ccclass
export default class PlayerFireControl extends cc.Component {
    @property
    Speed:number = 100;
    BulletBody:cc.RigidBody

    start () {
        //获得本组件刚体
        this.BulletBody = this.getComponent(cc.RigidBody);
        //当前角度转弧度
        let CurrentRad = cc.misc.degreesToRadians(this.node.angle);
        //弧度转向量算法
        let CurrentV2 = cc.v2 (0,1).rotate(CurrentRad);
        //按照当前向量移动
        this.BulletBody.linearVelocity = cc.v2(CurrentV2.x * this.Speed,CurrentV2.y * this.Speed);
    }

    onBeginContact(concat,slef,other){
        if (other.tag == 3) {
            other.getComponent(EnemyControl).died();
        } else if (other.tag == 5) {
            // console.debug(other.getComponent(WallControl))
            other.getComponent(WallControl).dest();
        }
        this.node.destroy();
    }
}
